package personal.wang.pekko;

import com.typesafe.config.ConfigFactory;
import org.apache.pekko.actor.AbstractActor;
import org.apache.pekko.actor.ActorRef;
import org.apache.pekko.actor.ActorSystem;
import org.apache.pekko.actor.Props;

import javax.annotation.processing.Messager;

public class Server extends AbstractActor {
    public static void main(String[] args) {
        ActorSystem actorSystem = ActorSystem.create("flink", ConfigFactory.load("test_server"));
        actorSystem.actorOf(Props.create(Server.class) , "server");
    }

    @Override
    public Receive createReceive() {
        return receiveBuilder().match(MessageRecord.class , this::messageHandler)
                .matchAny(this::handler).build();
    }

    private void messageHandler(MessageRecord messageRecord) {
        System.out.println("messageHandler:  " + messageRecord);
    }

    private void handler(Object o) {
        System.out.println(o);
        ActorRef sender = getSender();
        sender.tell("hello client" , getSender());
    }
}
